import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class StringAdd {
    public static void main(String[] args) {
        JFrame frame = new JFrame("字符串拼接");
        frame.setLayout(new BorderLayout());
        frame.setSize(400, 200);
        frame.setLocation(300, 300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel panel1 = new JPanel();
        JPanel panel2 = new JPanel();
        JPanel panel3 = new JPanel();
        JLabel strl1 = new JLabel("字符串1");
        JLabel strl2 = new JLabel("字符串2");
        JTextField str1 = new JTextField(5);
        JTextField str2 = new JTextField(5);
        JTextField str3 = new JTextField(10);
        JButton stradd = new JButton("两个字符串连接：");
        JButton strtry = new JButton("字符串1是否为字符串2的逆序");
        JRadioButton redio1 = new JRadioButton("是");
        JRadioButton redio2 = new JRadioButton("否");
        panel1.add(strl1);
        panel1.add(str1);
        panel1.add(strl2);
        panel1.add(str2);
        panel2.add(stradd);
        panel2.add(str3);
        panel3.add(strtry);
        panel3.add(redio1);
        panel3.add(redio2);
        frame.add(panel1, BorderLayout.PAGE_START);
        frame.add(panel2, BorderLayout.CENTER);
        frame.add(panel3, BorderLayout.PAGE_END);
        stradd.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String strmax = str1.getText() + str2.getText();
                str3.setText(strmax);
            }
        });
        strtry.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String strone = str1.getText();
                String strtwo = str2.getText();
                StringBuilder sb = new StringBuilder(strtwo);
                String strreveser = "";
                for (int i=sb.length()-1;i>=0;i--) {
                    strreveser+=sb.charAt(i);
                }
                System.out.println(strreveser);
                if(strone.equals(strreveser)){
                    redio1.setSelected(true);
                    redio2.setSelected(false);
                }else{
                    redio2.setSelected(true);
                    redio1.setSelected(false);

                }
            }
        });
        frame.setVisible(true);
    }
}
